1. Field of Invention
The present invention relates to a method of allocating a memory, and more particularly to a method of allocating a physical memory in a specified address range under a Linux system platform.
2. Related Art
Currently, a memory test plays a very important role in a hardware diagnosis solution, which mainly includes two parts: memory allocation and test algorithm. The test algorithm specifies the rules for reading and writing memories, and different test algorithms are directed to inspecting different types of memory errors. Relevant information about conventional test algorithms has been specially introduced in documents about memory test algorithms, which will not be repeated herein. The memory allocation is an important precondition for a memory read/write test, which directly influences whether the test effect may be achieved or not, for example, whether the true physical memory can be tested or whether the same memory is repeatedly tested. However, different operating systems manage physical memories in different manners, without uniform rules. Therefore, the memory allocation is relatively complicated, and should be performed in consideration of different operating systems.
Under a Linux operating system platform (a multi-user computer operating system free of charge), since no method of allocating a physical memory is provided in a user mode, it can do nothing but allocate a physical memory in a kernel through a driver and then provide an interface in the conventional method. However, in order to read and write a physical memory at will in the user mode, the allocated physical memory further needs to be mapped into a virtual address space in the user mode. At this point, the principles and methods in the conventional art are quite similar, which thus will not be repeated herein, and the main difference lies in the method of allocating a physical memory.
Currently, there are two methods of allocating a physical memory in the conventional art.
The first method is a method of allocating specified physical memory pages. In this method, the physical memory may be allocated in a specified address range, page is taken as the minimum unit for allocating physical memory, and the size of one page is determined depending upon the configuration of a Linux system kernel. However, this method can only allocate one memory page each time, has low efficiency, and may possibly occupy other adjacent memory pages, thereby resulting in wasting of resources. Therefore, this method has a great limitation and is not suitable for testing a large amount of physical memories.
The second method is to directly call an interface of continuous physical memories that have been allocated into memory blocks provided by the Linux system kernel. This method can be used to allocate a large amount of physical memories, which thus is suitable for testing a large amount of physical memories. However, the main disadvantage of this method lies in that, it cannot allocate the physical memories in a specified address range (due to being restricted by a data structure for organizing the physical memories in the Linux system kernel). Therefore, this method cannot be used to test specific memory units or memories in specified slots.